package com.ruiboyun.liveapp.util.tool;

import android.animation.TypeEvaluator;
import android.graphics.Point;

/**
 * Created by 落雁沙 on 2017/1/3.
 * Update by  on
 * 公司:杭州无尽信息科技有限公司
 * 邮箱：apple9302@126.com
 * Description:两阶贝塞尔曲线估值器
 */


public class BezierEvaluator implements TypeEvaluator<Point> {

    private Point controllPoint;

    public BezierEvaluator(Point controllPoint) {
        this.controllPoint = controllPoint;
    }

    @Override
    public Point evaluate(float t, Point startValue, Point endValue) {
        int x = (int) ((1 - t) * (1 - t) * startValue.x + 2 * t * (1 - t) * controllPoint.x + t * t * endValue.x);
        int y = (int) ((1 - t) * (1 - t) * startValue.y + 2 * t * (1 - t) * controllPoint.y + t * t * endValue.y);
        return new Point(x, y);
    }
}